package org.flashamaphone.tones
{
	/** 
	 * A set of several notes to play at the same time
	 */
	public class Polynote extends Polytone
	{
		/** current notes */
		protected var _notes:Vector.<Note>;
		
		/** 
		 * constructor
		 * 
		 * @param note designation
		 * @param octave
		 * @param duration
		 */
		public function Polynote(designations:Array = null, duration:Number = 1, octave:int = 4)
		{
			super();
			this.duration = duration;
			if (designations) {
				addNotes(designations, octave);
			}
		}
		
		/**
		 * get notations of notes in set
		 * 
		 * @return notations
		 */
		public function get notations():Array {
			var returnList:Array = new Array();
			for each (var note:Note in _notes) {
				returnList.push( note.notation );
			}
			return returnList;
		}
		
		/** 
		 * add note to set
		 * 
		 * @param note designation
		 * @param octave
		 */
		public function addNote(designation:String, octave:int = 4):Note {
			if (!_tones) {
				_tones = new Vector.<ITone>();
				_notes = new Vector.<Note>();
			}
			var note:Note = new Note(designation, octave, this.duration);
			_notes.push( note );
			_tones.push( note );
			return note;
		}
		
		/** 
		 * add notes to set
		 * 
		 * @param note designation
		 * @param octave
		 */
		public function addNotes(designations:Array, octave:int = 4):void {
			if (!_tones) {
				_tones = new Vector.<ITone>();
				_notes = new Vector.<Note>();
			}
			
			for each (var d:String in designations ) {
				addNote(d, octave);
			}
		}
		
		/** 
		 * clear notes in set
		 */
		public function clearNotes():void {
			_tones = new Vector.<ITone>();
			_notes = new Vector.<Note>();
		}
	}
}